package com.firemoss.atonement.example.contactmanager.view.model
{
	import com.firemoss.atonement.example.contactmanager.model.Company;
	import com.firemoss.atonement.example.contactmanager.model.Contact;
	
	import mx.collections.IList;
	import mx.collections.ListCollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;

	public class ContactListCollectionView extends ListCollectionView
	{
		
		private var _company : Company
		internal function set company( value : Company ) : void
		{
			_company = value
			refresh()
		}
		internal function get company() : Company
		{
			return _company
		}
		
		public function ContactListCollectionView( list : IList )
		{
			super( list )
			
			var sort : Sort = new Sort()
			sort.fields = [ 
				new SortField( "lastName", true ),
				new SortField( "firstName", true )
			];
			
			this.sort = sort;
			
			filterFunction = filter;
		}
		
		private function filter( contact : Contact ) : Boolean
		{
			return contact.company == company
		}
	}
}